package com.qf.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class BeanFactory {
    private static Map<String,Object> map = new HashMap<>();
    static {
        InputStream is = BeanFactory.class.getClassLoader().getResourceAsStream("bean.properties");
        Properties properties = new Properties();
        try {
            properties.load(is);

        } catch (IOException e) {
            e.printStackTrace();
        }

        Set<Object> keySet = properties.keySet();
        for (Object key : keySet) {
            String values = (String) properties.get(key);
            try {
                Class clazz = Class.forName(values);
                Object obj = clazz.newInstance();
                map.put((String)key,obj);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public static Object getBean(String key){
        return map.get(key);
    }
}
